package com.yf.course.modules.course.dto.response;

import com.yf.course.modules.course.dto.CourseLiveDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Calendar;
import java.util.Date;

/**
* <p>
* 课程直播数据传输类
* </p>
*
* @author 聪明笨狗
* @since 2021-12-03 19:31
*/
@Data
@ApiModel(value="课程直播", description="课程直播")
public class CourseLiveRespDTO extends CourseLiveDTO {

    private static final long serialVersionUID = 1L;
    
    

    @ApiModelProperty(value = "是否直播中")
    private Integer state;


    /**
     * 是否直播中
     * @return
     */
    public Integer getState(){

        if(super.getStartTime() == null || super.getDuration()==null){
            return 0;
        }

        // 直播尚未开始
        if(new Date().before(super.getStartTime())){
            return 0;
        }

        Calendar cl = Calendar.getInstance();
        cl.setTime(super.getStartTime());
        cl.add(Calendar.MINUTE, super.getDuration());

        // 直播中
        if(new Date().after(super.getStartTime()) && new Date().before(cl.getTime())){
            return 1;
        }

        // 已结束
        if(new Date().after(cl.getTime())){
            return 2;
        }

        return 0;
    }
    
}
